package com.qf.micrograss.grass.controller;


import com.qf.common.core.common.PageVO;
import com.qf.common.core.common.R;
import com.qf.micrograss.grass.param.GrassParam;
import com.qf.micrograss.grass.param.GrassSearchParam;
import com.qf.micrograss.grass.service.GrassService;
import com.qf.micrograss.grass.vo.GrassVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Classname GrassController
 * @Description
 * @Date 2025-05-28 11:16
 * @Created by 老任与码
 */
@RestController
@RequestMapping("/article")
public class GrassController {

    @Resource
    private GrassService grassService;

    /**
     * 添加文章
     * @param grassParam 文章参数
     * @return R
     */
    @PostMapping("/add")
    public R addGrass(@RequestBody GrassParam grassParam) {
        grassService.addGrass(grassParam);
        return R.ok();
    }


    /**
     * 文章分页
     * @param grassSearchParam 搜索参数
     * @return R
     */
    @GetMapping("/page")
    public R grassPage(GrassSearchParam grassSearchParam) {
        PageVO<GrassVO> page = grassService.grassPage(grassSearchParam);
        return R.ok(page);
    }



    @PostMapping("/upload/img")
    public R uploadImg(MultipartFile file) {
        // 上传图片：使用Minio上传图片
        String url = grassService.uploadImg(file);
        return R.ok(url);
    }
}
